package ru.lenwp.operation.client;

import ru.lenwp.context.Context;
import ru.lenwp.model.Account;
import ru.lenwp.model.Client;
import ru.lenwp.model.User;
import ru.lenwp.util.ConsoleUtil;

import java.util.ArrayList;

/**
 * Created by Lenar on 10.08.2014.
 */
public class AccountStatus {

    Context context;

    public AccountStatus(Context context) {
        this.context = context;
    }

    public void showAccountStatus() {
        boolean performed = false;
        while (!performed) {
            System.out.println("Введите номер счета:");
            String acc = ConsoleUtil.askString();
            Account account = null;
            for(User client : context.getUserDao().allUser()) {
                if (client instanceof Client) {
                    for (Account currentAccount : ((Client) client).getAccountList()) {
                        if (currentAccount.getNumber() != null && currentAccount.getNumber().equals(acc)) {
                            account = currentAccount;
                            break;
                        }
                    }
                }
            }
            if (account != null) {
                String firstName = String.valueOf(account.getClient().getFirstName());
                String lastName = String.valueOf(account.getClient().getLastName());
                String sumAccount = String.valueOf(account.getSum());

                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.append("Фамилия ").append(lastName).append("Имя ").append(firstName).append("Сумма на счету ").append(sumAccount);
                System.out.println(stringBuilder.toString());
                performed = true;
            }else {
                System.out.println("Введен не верный номер счета");
            }
        }
    }
}
